package com.Sep_Eight;


/**
 * 404. 左叶子之和
 * 给定二叉树的根节点 root ，返回所有左叶子之和。
 */

public class Solution404 {

    public int sumOfLeftLeaves(TreeNode root) {
        if (root==null) return 0;
        int tempVal=0;
        if (root.left!=null&&root.left.left==null&&root.left.right==null)
        {
            tempVal= root.left.val;
        }
        return tempVal+sumOfLeftLeaves(root.left)+sumOfLeftLeaves(root.right);
    }

    private class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

}
